<?php

declare(strict_types=1);

namespace App\Controller\User;


use App\Controller\BaseController;
use App\Request\User\CanCancelAccountRequest;
use App\Request\User\JudgeGoldRequest;
use App\Services\User\AccountService;
use Hyperf\Context\Context;
use Hyperf\Di\Annotation\Inject;
use Psr\Http\Message\ResponseInterface;

class AccountController extends BaseController
{
    #[Inject]
    public AccountService $accountService;

    /**
     * Note - 用户是否能注销账号
     * DateTime 2024/7/17 18:14
     * User Admin
     */
    public function canCancelAccount(CanCancelAccountRequest $request)
    {
        $params = $this->request->post();
        $request->execute($params);

        $result = $this->accountService->canCancelAccount($params['imei']);
        return $this->return($result);

    }

    /**
     * Note - 注销账号
     * DateTime 2024/7/18 10:21
     * User Admin
     */
    public function cancelAccount(CanCancelAccountRequest $request)
    {
        // $request->validateResolved();
        $params = $this->request->post();
        $request->execute($params);
        $result = $this->accountService->cancelAccount($params['imei']);
        return $this->return($result);

    }

    /**
     * Note - 判断用户金币是否足够
     * DateTime 2024/7/18 15:45
     * User Admin
     * @param JudgeGoldRequest $request
     * @return ResponseInterface
     */
    public function judgeGold(JudgeGoldRequest $request)
    {
        $params = $this->request->post();
        $request->execute($params);
        $user = Context::get('user');
        $type = $params['type'] ?? 0;    // 0文字消息 1礼物 2语音消息 3图片消息 4通话
        $giftId = $params['gift_id'] ?? 0;  // 礼物id
        $userId = $params['user_id'] ?? 0;  // 对方用户id

        $result = $this->accountService->judgeGold($user['id'], $type, $giftId, $userId);
        return $this->return($result);
    }


}
